package com.bawei.mall.product.controller;

import com.bawei.common.core.domain.R;
import com.bawei.mall.product.domain.Dto.OrderDot;
import com.bawei.mall.product.domain.Vo.OrderListVo;
import com.bawei.mall.product.domain.Vo.OrderVo;
import com.bawei.mall.product.service.IOrderService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author：liurui
 * @Package：com.bawei.mall.search.controller
 * @Project：mall_cloud
 * @name：ShoppingCartController
 */
@RestController
@Log4j2
@RequestMapping("/order")
public class COrderController {
    @Autowired
    private IOrderService service;


    /**
     * 生成订单
     */
    @PostMapping("/generateConfirmOrder")
    public R<OrderVo> generateConfirmOrder(@RequestBody Integer[] cartIds){
        OrderVo orderVo=service.generateConfirmOrder(cartIds);
        return R.ok(orderVo);
    }

    /**
     * 订单提交
     */
    @PostMapping("/generateOrder")
    public R generateOrder(@RequestBody OrderDot orderDot){
        service.generateOrder(orderDot);
        return R.ok();
    }

    /**
     * 我的订单，全部订单
     */
    @GetMapping("/list")
    public R<PageInfo<OrderListVo>> list(@RequestParam Integer status, @RequestParam Integer pageNum, @RequestParam Integer pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<OrderListVo> list=service.list(status);
        PageInfo<OrderListVo> pageInfo = new PageInfo<>(list);
        return R.ok(pageInfo);
    }

}
